package com.ruoyi.waterPrice.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.business.waterPrice.WiFarmfeeY;
import com.ruoyi.waterPrice.service.IWiFarmfeeYService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 农户水费核算Controller
 *
 * @author ps
 * @date 2023-02-16
 */
@RestController
@RequestMapping("/WiFarmfeeY")
public class WiFarmfeeYController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(WiFarmfeeYController.class);

    @Autowired
    private IWiFarmfeeYService wiFarmfeeYService;


    /**
     * 查询农户水费核算列表
     */
    @RequiresPermissions("waterPrice:WiFarmfeeY:list")
    @GetMapping("/list")
    public TableDataInfo list(WiFarmfeeY wiFarmfeeY) {
        startPage();
        List<WiFarmfeeY> list = wiFarmfeeYService.selectWiFarmfeeYList(wiFarmfeeY);
        return getDataTable(list);
    }

    /**
     * 导出农户水费核算列表
     */
    @RequiresPermissions("waterPrice:WiFarmfeeY:export")
    @Log(title = "农户水费核算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WiFarmfeeY wiFarmfeeY) {
        List<WiFarmfeeY> list = wiFarmfeeYService.selectWiFarmfeeYList(wiFarmfeeY);
        ExcelUtil<WiFarmfeeY> util = new ExcelUtil<WiFarmfeeY>(WiFarmfeeY.class);
        util.exportExcel(response, list, "农户水费核算数据");
    }

    /**
     * 获取农户水费核算详细信息
     */
    @RequiresPermissions("waterPrice:WiFarmfeeY:query")
    @GetMapping(value = "/{feeYr}/{farmCd}")
    public AjaxResult getInfo(@PathVariable("feeYr") String feeYr, @PathVariable("farmCd") String farmCd) {
        return success(wiFarmfeeYService.selectWiFarmfeeYByFeeYrAndFarmCd(feeYr, farmCd));
    }

    /**
     * 新增农户水费核算
     */
    @RequiresPermissions("waterPrice:WiFarmfeeY:add")
    @Log(title = "农户水费核算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WiFarmfeeY wiFarmfeeY) {
        return toAjax(wiFarmfeeYService.insertWiFarmfeeY(wiFarmfeeY));
    }

    /**
     * 修改农户水费核算
     */
    @RequiresPermissions("waterPrice:WiFarmfeeY:edit")
    @Log(title = "农户水费核算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WiFarmfeeY wiFarmfeeY) {
        return toAjax(wiFarmfeeYService.updateWiFarmfeeY(wiFarmfeeY));
    }

    /**
     * 删除农户水费核算
     */
    @RequiresPermissions("waterPrice:WiFarmfeeY:remove")
    @Log(title = "农户水费核算", businessType = BusinessType.DELETE)
    @DeleteMapping("/{feeYrs}")
    public AjaxResult remove(@PathVariable String[] feeYrs) {
        return toAjax(wiFarmfeeYService.deleteWiFarmfeeYByFeeYrs(feeYrs));
    }
}
